package com.gxan.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gxan.common.R;
import com.gxan.pojo.Resume;
import com.gxan.service.ResumeService;
import com.gxan.service.impl.ResumeServiceImpl;
import com.gxan.utils.DateUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/resume/updateResume")
public class EditResumeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取前端传过来的参数
        String resume_id = request.getParameter("resume_id");
        String job_title = request.getParameter("job_title");
        String job_code = request.getParameter("job_code");
        String job_classification = request.getParameter("job_classification");
        String name = request.getParameter("name");
        String sex = request.getParameter("sex");
        String recruitment_type = request.getParameter("recruitment_type");
        String email = request.getParameter("email");
        String phone = request.getParameter("phone");
        String registered_residence = request.getParameter("registered_residence");
        String address = request.getParameter("address");
        String political_landscape = request.getParameter("political_landscape");
        String id_number = request.getParameter("id_number");
        String graduate_school = request.getParameter("graduate_school");
        String education_background = request.getParameter("education_background");
        String major = request.getParameter("major");
        String work_experience = request.getParameter("work_experience");
        String salary_requirement = request.getParameter("salary_requirement");
        String whether_in_office = request.getParameter("whether_in_office");
        String fresh_graduate = request.getParameter("fresh_graduate");
        String registration_time = request.getParameter("registration_time");
        String personal_resume = request.getParameter("personal_resume");
        //String resume_attachment = request.getParameter("resume_attachment");
        String recommend_the_interview = request.getParameter("recommend_the_interview");
        String referrer = request.getParameter("referrer");
        String the_recommended_time = request.getParameter("the_recommended_time");
        String recommended_interview_advice = request.getParameter("recommended_Interview_advice");
        //封装对象
        Resume resume = new Resume(Integer.valueOf(resume_id),job_title,job_code,
                job_classification,name,sex,recruitment_type,email,phone,
                registered_residence,address,political_landscape,id_number,
                graduate_school,education_background,major,work_experience,
                Integer.valueOf(salary_requirement),whether_in_office,fresh_graduate,
                DateUtils.string2Date(registration_time),personal_resume,null,recommend_the_interview,
                referrer, DateUtils.string2Date(the_recommended_time),recommended_interview_advice
        );
        //传递service处理数据
        System.out.println(resume);
        //传递service处理数据
        ResumeService resumeService =new ResumeServiceImpl();
        R r = resumeService.updateResume(resume);
        //响应到前端页面
        //返回给前端需要的R封装的数据，装换成Json方式返回
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JSONObject.toJSONString(r));
        response.getWriter().flush();
        response.getWriter().close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
